package DivorceTopOne4;

        import org.apache.hadoop.io.WritableComparable;

        import java.io.DataInput;
        import java.io.DataOutput;
        import java.io.IOException;

public  class DivorceBean implements WritableComparable<DivorceBean> {

    private String province;//省
    private String city;//区市
    private float divorce;//离婚数

    public DivorceBean() {
    }

    public DivorceBean(String province, String city, float divorce) {
        this.province = province;
        this.city = city;
        this.divorce = divorce;
    }

    public void set(String province, String city,  float divorce) {
        this.province = province;
        this.city = city;
        this.divorce = divorce;
    }

    public String getProvince(){
        return province;
    }
    public void setProvince(String province){
        this.province = province;
    }

    public String getCity(){
        return city;
    }
    public void setCity(String city){
        this.city =city;
    }


    public float getDivorce() {
        return divorce;
    }

    public void setDivorce(float divorce) {
        this.divorce = divorce;
    }


    @Override
    public String toString() {
        return " " +
                "省份=" + province + '\'' +
                ",市=" + city + '\'' +
                ",离婚登记数=" + divorce +
                ' ';

    }

    @Override
    public int compareTo(DivorceBean o) {

        int result;
        int i = province.compareTo(o.getProvince());
        if ( i > 0) {
            result = 1;
        } else if (i <0 ) {
            result = -1;
        } else {
            // 离婚登记数倒序排序
            result = this.divorce > o.getDivorce() ? -1: (this.divorce < o.getDivorce()? 1:0);
        }
        return result;

                                         //>0 ? 1:-1
        // return this.divorce - o.divorce <0 ? -1:1;

    }

    @Override
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeUTF(province);
        dataOutput.writeUTF(city);
        dataOutput.writeFloat(divorce);
    }

    @Override
    public void readFields(DataInput dataInput) throws IOException {
        this.province = dataInput.readUTF();
        this.city = dataInput.readUTF();
        this.divorce = dataInput.readFloat();
    }
}